//
//  LJFHotCollectionViewCell.m
//  GiftThat
//
//  Created by 刘景峰 on 16/1/7.
//  Copyright © 2016年 ChuXiang. All rights reserved.
//

#import "LJFHotCollectionViewCell.h"

@implementation LJFHotCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectZero];
        self.imageView.backgroundColor = [UIColor grayColor];
        [self addSubview:self.imageView];
        

        self.whiteView = [[UIView alloc]initWithFrame:CGRectZero];
        self.whiteView.backgroundColor = [UIColor whiteColor];
//       self.whiteView.backgroundColor = [UIColor colorWithRed:35 / 255.0 green:34 / 255.0 blue:38 / 255.0 alpha:1.0];
        
        [self.contentView addSubview:self.whiteView];
        
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        [self.titleLabel setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:13]];

        self.titleLabel.font = [UIFont systemFontOfSize:13];
        self.titleLabel.textAlignment = UIControlContentVerticalAlignmentFill;
        self.titleLabel.numberOfLines = 0;
        [self.contentView addSubview:self.titleLabel];
        
        self.moneyLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        [self.moneyLabel setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:12]];
        [self.moneyLabel setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:13]];
        self.moneyLabel.textColor = [UIColor redColor];
        [self.contentView addSubview:self.moneyLabel];
        
        
        self.zanImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
        [self.contentView addSubview:self.zanImageView];
        
        self.zanLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        self.zanLabel.font = [UIFont systemFontOfSize:12];
        self.zanLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.zanLabel];
        
        
        
        
        
    }
    return self;
}

-(void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    
    self.imageView.frame = CGRectMake(5, 0, self.width - 10, self.height * 0.6);
    
    self.titleLabel.frame = CGRectMake(5, self.imageView.height + 10, self.width - 10, self.height / 5);
    
    self.moneyLabel.frame = CGRectMake(5, self.titleLabel.bottom + 5, self.titleLabel.width / 2, self.titleLabel.height / 4 * 3);

    self.zanImageView.frame = CGRectMake(self.moneyLabel.right + 15, self.titleLabel.bottom + 12, self.moneyLabel.height / 2, self.moneyLabel.height / 2);
    
    self.zanLabel.frame = CGRectMake(self.zanImageView.right, self.moneyLabel.top, self.titleLabel.width - 15 - self.moneyLabel.width - self.zanImageView.width, self.moneyLabel.height);
    
    self.whiteView.frame = CGRectMake(self.imageView.left, self.imageView.bottom, self.imageView.width, self.height * 0.4);
    
    
}

-(void)setLjfmodel:(LJFModel *)ljfmodel{
    
    if (_ljfmodel != ljfmodel) {
        _ljfmodel = ljfmodel;
    }
   
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.ljfmodel.cover_image_url] placeholderImage:[UIImage imageNamed:@"holder"]];
    
    NSString *string = @"￥";
    NSString *newString = [string stringByAppendingString:self.ljfmodel.price];
    self.moneyLabel.text = newString;
    
    self.titleLabel.text = self.ljfmodel.name;
    
    self.zanLabel.text = [NSString stringWithFormat:@"%@",self.ljfmodel.favorites_count];
    
    self.zanImageView.image = [UIImage imageNamed:@"SmallFavorite"];
//    夜间模式换cell得背景颜色
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Color"] isEqualToString:@"BlackColor"]) {
        self.whiteView.backgroundColor = [UIColor blackColor];
        self.titleLabel.textColor = [UIColor whiteColor];

    }else{
        self.whiteView.backgroundColor =  [UIColor whiteColor];
        self.titleLabel.textColor = [UIColor blackColor];
    }

    
}

@end
